package com.wangzhen.spring.resource;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import java.io.IOException;

/**
 * 根据通配符找到一组文件列表
 */
public class PathMatcherResolverDemo {
    public static void main(String[] args) throws IOException {
        // 工作目录
        String userDir = System.getProperty("user.dir");
        // 这么写的一个好处是如果别人clone了这段代码，不需要修改路径可以直接run
        String dir = "file://" + userDir + "/" +
                "spring-resource/src/main/java/com/wangzhen/spring/resource/*.java";
        System.out.println(dir);

        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] resources = resolver.getResources(dir);
        for (Resource resource : resources) {
            System.out.println(IOUtils.toString(resource.getInputStream()));
        }
    }
}
